package com.atguigu.service.impl;


import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.dao.Memberdao;
import com.atguigu.dao.UserDao;
import com.atguigu.pojo.Member;
import com.atguigu.service.MemberService;
import com.atguigu.vo.LoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    @Autowired
    Memberdao memberdao;
    @Autowired
    UserDao userDao;
    @Override
    public void login(LoginVo loginVo) {
        //判断数据库是否有用户信息
        Member member = memberdao.selectTelepthone(loginVo.getTelephone());
        if (member==null){
            //添加用户信息
             member = new Member();
             member.setPhoneNumber(loginVo.getTelephone());
             member.setRegTime(new Date());
            memberdao.insert(member);
        }
    }

    @Override
    public Member selectIdCard(String idCard) {
        return memberdao.selectIdCard(idCard);
    }

    @Override
    public void insert(Member member) {
        memberdao.insert(member);
    }

    @Override
    public List<Integer> getMemberMonth(ArrayList<String> list) {
        List<Integer> collect = list.stream().map(item -> {
            Integer count = memberdao.getMemberMonth(item);
            return count;
        }).collect(Collectors.toList());
        return collect;
    }

    @Override
    public Integer selectDate(String day) {
        return memberdao.selectDay(day);
    }

    @Override
    public Integer selectAll() {
        return memberdao.selectAll();
    }

    //一周内增加的会员数
    @Override
    public Integer selectWeek(Date weekMonday, Date lastDay) {
        return memberdao.selectWeek(weekMonday,lastDay);
    }

    @Override
    public Integer selectMonth(String MonthString) {
        return memberdao.selectMonth(MonthString);
    }
}
